﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Threading;

namespace DisplayBoardInfo.Server.Forms.Board
{
    /// <summary>
    /// Interaction logic for InRoom.xaml
    /// </summary>
    public partial class InRoom : UserControl
    {
        private Network.Messages.Content.Patient patient;
        private DispatcherTimer timer;
        private int seconds, minutes;

        public InRoom()
        {
            InitializeComponent();

            timer = new DispatcherTimer();
            timer.Interval = TimeSpan.FromSeconds(1);
            timer.Tick += new EventHandler(timer_Tick);
        }

        void timer_Tick(object sender, EventArgs e)
        {
            seconds++;
            if (seconds == 60)
            {
                seconds = 0;
                minutes++;
            }

            timeLabel.Content = String.Format("{0}:{1}", Helpers.Convert.NumbersToString(minutes), Helpers.Convert.NumbersToString(seconds));
        }

        public Network.Messages.Content.Patient Patient
        {
            set
            {
                patient = value;
                Start();
            }
        }

        public void Hide()
        {
            this.Visibility = System.Windows.Visibility.Hidden;
        }

        private void Start()
        {
            seconds = 0;
            minutes = 0;

            patientLabel.Content = patient.Name + " " + patient.LastName;
            timer.Start();

            this.Visibility = System.Windows.Visibility.Visible;
        }
    }
}
